//
//  PayJiHuoMaViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/7.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "PayJiHuoMaViewController.h"
#import "JTCSM.h"
#import "MyInfoView.h"
#import "ZYRadioButton.h"
#import "JiHuoMaView.h"
#import "ZhifuView.h"
static CGFloat imageviewHeight = 160;
static CGFloat space = 45;
@interface PayJiHuoMaViewController ()<UIAlertViewDelegate>
{
    UILabel *numberLabel;
    UILabel *goumiaxuzhiLabel;
    NSString *type;
}
@end

@implementation PayJiHuoMaViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}

- (void)gotobackVC{
//    [self.view removeFromSuperview];
//    [self removeFromParentViewController];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad{
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;
//    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, KCONTROLLERWith, KCONTROLLERHeight-30)];
//    backScrollV.backgroundColor = [UIColor whiteColor];
//    backScrollV.userInteractionEnabled = YES;
//    backScrollV.bounces = NO;
//    backScrollV.showsVerticalScrollIndicator = NO;
//    [self.view addSubview:backScrollV];
    type = @"";
    
   

    
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,KCONTROLLERWith , imageviewHeight+KagainChangeHeight)];
    imageview.image = [UIImage imageNamed:@"activity_buy_code_iv1.png"];
    [self.view addSubview:imageview];
    imageview.userInteractionEnabled = YES;
    [self.view addSubview:[UILabel initWithFrame:CGRectMake(0, 20, KCONTROLLERWith, 44) text:@"购买激活码" font:22 textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:[UIColor clearColor]]];
    
    UIButton *button = [[UIButton alloc] init];
    button.frame = CGRectMake(10, 20, 60, 44);
    [button setImage:[UIImage imageNamed:@"return_iv_white.png"] forState:UIControlStateNormal];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    //        image的位置大小调整
    button.imageEdgeInsets = UIEdgeInsetsMake(12.5, 5, 12.5, 40);
    //        title的位置大小调整
    button.titleEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    [button addTarget:self action:@selector(gotobackVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    UIImageView *image2view = [[UIImageView alloc]initWithFrame:CGRectMake(0,imageviewHeight+KagainChangeHeight,KCONTROLLERWith , imageviewHeight)];
    image2view.image = [UIImage imageNamed:@"activity_buy_code_iv2.png"];
    [self.view addSubview:image2view];
    image2view.userInteractionEnabled = YES;
    
    CGFloat labelHeight = 40;
    numberLabel =[UILabel initWithFrame:CGRectMake(space, KVIEW_Y(imageview)-labelHeight-10, KCONTROLLERWith-2*space, labelHeight) text:@"6222 9999 6929 604639" font:(KSCREENWidth==375?23:(KSCREENWidth==320?18:25)) textAlignment:NSTextAlignmentCenter texcolor:[UIColor blackColor] backgroundColor:[UIColor clearColor]];
    [imageview addSubview:numberLabel];
    CGFloat tiaoxingmaImageVHeight = 60;
    UIImageView *tiaoxingmaImagev = [[UIImageView alloc]initWithFrame:CGRectMake(space,KVIEW_Y(imageview)-10-tiaoxingmaImageVHeight-labelHeight,KCONTROLLERWith -2*space, tiaoxingmaImageVHeight)];
    tiaoxingmaImagev.image = [UIImage imageNamed:@"tiaoxingma.png"];
    [imageview addSubview:tiaoxingmaImagev];
    tiaoxingmaImagev.userInteractionEnabled = YES;
    
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(space, 10, KCONTROLLERWith-2*space, 30) text:@"购买须知：" font:18 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:[UIColor clearColor]];
    [image2view addSubview:titleLabel];
    
   goumiaxuzhiLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(titleLabel), KCONTROLLERWith-2*space, labelHeight*3/2) text:[JiHuoMaView shareSingle].payknow font:14 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:[UIColor clearColor]];
    goumiaxuzhiLabel.numberOfLines = 3;
    [image2view addSubview:goumiaxuzhiLabel];
    
    
    UILabel *payWayLabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(image2view)-10, KCONTROLLERWith-0, labelHeight) text:@"    选择支付方式" font:20 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:RGBACOLOR(241, 241, 241, 1)];
    [self.view addSubview:payWayLabel];
    NSArray *array1 = @[@"微信支付",@"支付宝支付"];
    MyInfoView *view2;
    for (int i = 0; i < array1.count; i++) {
        view2 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(payWayLabel)+labelHeight*i, KCONTROLLERWith, labelHeight) imagename:[NSString stringWithFormat:@"icon_0%d@2x.png",i+5] title:array1[i] placeholder:nil isShowLabel:RadioButton radioBtnIndex:i GroupId:@"paywayBtn"];
        view2.tag = 102+i;
        view2.userInteractionEnabled = YES;
        [ZYRadioButton addObserverForGroupId:@"paywayBtn" observer:self];
        [self.view addSubview:view2];
    }
    CGFloat btnspace = 20;
    CGFloat btnHeight = (KSCREENWidth ==320)?40:50;
    UIButton *LoginBtn =[[UIButton alloc] initWithFrame:CGRectMake(btnspace, KVIEW_Y(view2)+20 , (KCONTROLLERWith-2*btnspace), btnHeight)];
    LoginBtn.backgroundColor =RGBACOLOR(227, 68, 40, 1);
    [LoginBtn setTitle:@"立即支付" forState:UIControlStateNormal];
    [LoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //[df layerWithView:LoginBtn radius:4 width:2 color:RGBACOLOR(172,134,171, 1)];
    [LoginBtn addTarget:self action:@selector(gotoPay) forControlEvents:UIControlEventTouchUpInside];
    LoginBtn.tag = 10002;
    [self.view addSubview:LoginBtn];
    [df layerWithView:LoginBtn radius:btnHeight/2 width:0 color:nil];
}
- (void)gotoPay{
    
//    OrderBarcode/create

    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"OrderBarcode/create") withDict:@{@"token":KTokenString,@"type":type} superView:self.view isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            NSDictionary *dict = KResultOfKey(@"data");
            
            [[ZhifuView shareSingle] setMoney:[dict objectForKey:@"total_price"] imagename:[dict objectForKey:@"qrcode"] saveIamge:[dict objectForKey:@"poster"]];
//            [self getNumber];
        }else{
            [df showAlertWithTitle:KResultOfKey(@"msg") message:nil btn1:@"确定" btn2:nil btn3:nil delegate:nil tag:13];
        }
        
    }];

}


- (void)getNumber{
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"OrderBarcode/detail") withDict:@{@"token":KTokenString} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
//            JIhuoViewController *vc = [[JIhuoViewController alloc]init];
//            vc.labelNumber = [KResultOfKey(@"data") objectForKey:@"barcode"];
//            vc.type = @"1";
//            [self.navigationController pushViewController:vc animated:YES];
            [[ZhifuView shareSingle] setValue:@"" forKey:@""];
        }else{
            [df showAlertWithTitle:KResultOfKey(@"msg") message:nil btn1:@"确定" btn2:nil btn3:nil delegate:nil tag:0];
        }
        
    }];
    
    
}

-(void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString*)groupId{
    
    if (index == 0) {
        //微信
        NSLog(@"微信");
        type = @"1";
        
    }
    if (index == 1) {
        //支付宝
        NSLog(@"支付宝");
        type = @"2";

    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
